<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../../../../css/mui.min.css" rel="stylesheet" />
		<link href="../../css/css.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="../../../../css/mui.picker.min.css" />
		<link rel="stylesheet" type="text/css" href="../../../../css/mui.poppicker.css" />
		<!--<script type="text/javascript" src="../chaxun/js/mui.js"></script>-->
		<style type="text/css">
			.mui-bar~.mui-content .mui-fullscreen {
				top: 44px;
				height: auto;
			}
			
			.mui-pull-top-tips {
				position: absolute;
				top: -20px;
				left: 50%;
				margin-left: -25px;
				width: 40px;
				height: 40px;
				border-radius: 100%;
				z-index: 1;
			}
			
			.mui-bar~.mui-pull-top-tips {
				top: 24px;
			}
			
			.mui-pull-top-wrapper {
				width: 42px;
				height: 42px;
				display: block;
				text-align: center;
				background-color: #efeff4;
				border: 1px solid #ddd;
				border-radius: 25px;
				background-clip: padding-box;
				box-shadow: 0 4px 10px #bbb;
				overflow: hidden;
			}
			
			.mui-pull-top-tips.mui-transitioning {
				-webkit-transition-duration: 200ms;
				transition-duration: 200ms;
			}
			
			.mui-pull-top-tips .mui-pull-loading {
				/*-webkit-backface-visibility: hidden;
			-webkit-transition-duration: 400ms;
			transition-duration: 400ms;*/
			
				margin: 0;
			}
			
			.mui-pull-top-wrapper .mui-icon,
			.mui-pull-top-wrapper .mui-spinner {
				margin-top: 7px;
			}
			
			.mui-pull-top-wrapper .mui-icon.mui-reverse {
				/*-webkit-transform: rotate(180deg) translateZ(0);*/
			}
			
			.mui-pull-bottom-tips {
				text-align: center;
				background-color: #efeff4;
				font-size: 15px;
				line-height: 40px;
				color: #777;
			}
			
			.mui-pull-top-canvas {
				overflow: hidden;
				background-color: #fafafa;
				border-radius: 40px;
				box-shadow: 0 4px 10px #bbb;
				width: 40px;
				height: 40px;
				margin: 0 auto;
			}
			
			.mui-pull-top-canvas canvas {
				width: 40px;
			}
			
			body,
			.mui-content {
				background-color: #FFFFFF;
			}
			
			.mui-bar .mui-title {
				right: 80px;
				left: 80px;
			}
			
			.yxj-row,
			.yxj-rowxb,
			.yxj-rowxl {
				width: 92%;
				margin-left: 4%;
				padding: 10px;
				border-bottom: 1px solid #eaeaea;
				position: relative;
			}
			
			.marbtm {
				margin-bottom: 3px;
				white-space: nowrap;
				overflow: hidden;
				text-overflow: ellipsis;
			}
			
			.colorA3A3A3 {
				color: #A3A3A3;
			}
			
			.color1A5186 {
				color: #1A5186;
			}
			
			.flex {
				display: flex;
			}
			
			.justcnt {
				justify-content: space-between;
			}
			
			.fontsize13 {
				font-size: 13px;
			}
			
			.fontsize14 {
				font-size: 14px;
			}
			
			.fontsize15 {
				font-size: 15px;
			}
			
			.dsh-btn {
				color: #ffffff;
				background-color: #1A5186;
				border-radius: 3px;
				width: 80px;
				padding: 3px 0px;
				text-align: center;
				position: absolute;
				right: 10px;
				top: 45px;
				font-size: 13px;
			}
			
			.dsh-btnlock {
				background-color: #eee;
				border: 1px solid #1A5186;
				color: #1A5186;
			}
			
			.dsh-btnxb {
				top: 65px;
			}
			
			.wifi {
				width: 80%;
				margin: 100px auto;
				text-align: center;
			}
			
			.wifi img {
				width: 80%;
				margin-right: 20px;
			}
			
			.wifi p {
				font-size: 1rem;
			}
			
			[v-cloak] {
				display: none;
			}
			
			.tabbtn {
				display: flex;
				width: 100%;
				align-items: center;
				justify-content: space-evenly;
				margin-top: 5px;
			}
			
			.tabbtn div {
				width: 80px;
				height: 36px;
				line-height: 36px;
				text-align: center;
				font-size: 14px;
			}
			
			.tabbtn .active {
				color: #1A5186;
				border-bottom: 2px solid #004A86;
			}
			
			.red {
				color: red
			}
			
			.yellow {
				color: goldenrod;
			}
			
			.gray {
				background-color: darkgray;
			}
			
			.scanfix {
				position: fixed;
				bottom: 10px;
				width: 40%;
				margin-left: 30%;
				display: none;
				text-align: center;
				z-index: 1000000;
			}
			
			.line2 {
				width: 100%;
				height: 3px;
				background-color: #eaeaea;
				margin: 1px;
			}
			
			.mui-bar-nav,
			.mui-bar {
				box-shadow: 0px 0px 0px #ccc;
				-webkit-box-shadow: 0px 0px 0px #ccc;
			}
			
			.color1A5186 {
				color: #1A5186;
			}
			
			.xjperson {
				width: 70px;
				font-size: 14px;
				text-align: left;
			}
			
			.ppset {
				text-align: center;
				font-size: 14px;
				border-radius: 2px;
				width: 50px;
				height: 25px;
				line-height: 25px;
				color: #1A5186;
				border: 1px solid #1A5186
			}
			
			.ppshow {
				width: 100%;
				padding: 10px 10px 0;
				text-align: center;
			}
			
			.arrowshow {
				width: 100%;
				height: 16px;
				text-align: center;
			}
			
			.ppselect {
				background-color: #f7f7f7;
				display: flex;
				justify-content: center;
				align-items: center;
			}
			.deleteme{
				position: relative;
				border: 1px solid #696C76;
				padding: 0px 7px;
				border-radius: 3px;
				margin-right: 3px;
			}
			.deleteimg{
				position: absolute;
				top: 0px;
				right: 0px;
			}
			.mtop3{
				margin-bottom: 3px;
			}
			.zhs{
				width: 100%;
				display: flex;
				justify-content: space-between;
			}
			
			.mui-search{width: 82%;margin:10px 10px 10px 10px;}
			.p-search{display: flex;font-size: 14px;background-color:rgba(244, 244, 244, 1);height:54px;}
			.p-search input{background:#fff;}.mui-search::before{margin:-10px 0 0;}
			.p-search a{color:#09BB07;line-height:54px;height:54px;}.p-list{display: flex;}
			
			.tabbtn .mui-active {
				color: #1A5186!important;
				border-bottom: 2px solid #004A86!important;
			}
			
			.mui-slider .mui-segmented-control.mui-segmented-control-inverted .mui-control-item.mui-active:after {
				height: 0px !important;
			}
			.mui-pull-bottom-tips{
				background-color: #ffffff!important;
			}
			.mui-slider .mui-segmented-control.mui-segmented-control-inverted~.mui-slider-group .mui-slider-item{
				border-top:0px !important;
			}
			.line2{
				width: 100%;
				height: 3px;
				background-color: #eaeaea;
				margin-top: -1px;
			}
			.mui-bar-nav,.mui-bar{
				box-shadow: 0px 0px 0px #ccc;
				-webkit-box-shadow: 0px 0px 0px #ccc; 
			}
		</style>
	</head>

	<body>
		<div class="mui-content mui-scroll-wrapper" id="refreshContainer" v-cloak>
			<div class="mui-scroll">
				<div style="position: relative;">
					<div class="mui-row yxj-row" style="position: relative;" v-for="(item,index) in data" :key="index">
						<div class="yxj-row-1" @click="getChildPage(item)">
							<div class="marbtm flex justcnt">
								<div class="marbtm fontsize15 zhs">
									<span class="fontsize15">{{changeState(item.name)}}</span>
									<span class="color1A5186 fontsize15" v-show="item.realname">执行人:{{item.realname}}</span>
								</div>
								<div v-if="item.helpstatus == '1'">
									<span class="dsh-btn" style="width: 40px;right: 60px;" @click.stop="handleTask(item,'3')">同意</span>
									<span class="dsh-btn" style="width: 40px;" @click.stop="handleTask(item,'2')">拒绝</span>
								</div>
								<div v-if="!item.helpstatus">
									<span class="dsh-btn" @click.stop="getTask(item,'1')" v-if="item.sxlstatus == '0'">{{item.status == 1 ? '领取任务' : '巡检中'}}</span>
									<span class="dsh-btn" :class="item.status == '1' ? 'dsh-btnlock' : ''"
										v-if="item.sxlstatus == '1'">{{item.status == 1 ? '已锁定' : '巡检中'}}</span>
								</div>
							</div>
							<div class="colorA3A3A3 fontsize13">开始时间：{{item.start_time}}</div>
							<div class="colorA3A3A3 fontsize13" :class="getCheckTime(item.latestcompletetime)">
								最晚完成时间：{{item.latestcompletetime}}</div>
						</div>
						<div class="ppselect" v-show="item.status != 1 && !item.helpstatus">
							<div class="arrowshow" v-show="item.visible == 0" @click="getVisible(item,'syz')">
								<img style="width:16px" src="../../../../img/arrowbottom.png" />
							</div>
							<div v-show="item.visible == 1"  class="ppshow">
								<div class="flex justcnt">
									<div style="width: 90%;">
										<div class="flex" style="width: 100%;">
											<div class="xjperson" style="width: 25%;">设置人员</div>
											<div style="display: flex;flex-wrap: wrap;width: 75%;">
												<div v-for="(hp,i) in item.helperList" :key="i" class="colorA3A3A3 fontsize14 deleteme mtop3" @click="deleteName(hp.id)">
													{{hp.name}}
													<img src="../../../../img/delete.png" width="8px" class="deleteimg">
												</div>
											</div>
										</div>
										<div class="flex">
											<div class="xjperson">同意人</div>
											<div class="colorA3A3A3 fontsize14">{{item.agreers}}</div>
										</div>
										<div class="flex">
											<div class="xjperson">拒绝人</div>
											<div class="colorA3A3A3 fontsize14">{{item.refusers}}</div>
										</div>
									</div> 
									<div class="ppset" v-show="item.assist_button == '1'" @click="getPeople(item,1)">
										设置
									</div>
								</div>
								<img style="width:16px" @click="getVisible(item)" src="../../../../img/arrowtop.png" />
							</div> 
						</div>
					</div>
				</div>
			</div>
		</div>
		<script src="../../../../js/mui.min.js"></script>
		<script type="text/javascript" src="../../../../js/mkeyplus.base.xunjian.js"></script>		
		<script type="text/javascript" src="../../../../js/vue.js"></script>
		<script src="../../../../js/jquery-3.2.1.min.js"></script>
		<script>
			 
			mui.init({
				pullRefresh: {
					container: "#refreshContainer",           
					down: {
						callback: pulldown
					},
					up: {
						auto:true,
						callback: pullup
					}
				}
			});
			
			window.vm = new Vue({
				el: "#refreshContainer",
				data: {
					data: [],
					data1: [],
					data2: [],
					tabindex: 1,
					ifshow: false,
					ifshow1: false,
					ifshow2: false,
					pageSize: 10,
					pageNumber: 1,
					pageSize1: 10,
					pageNumber1: 1,
					pageSize2: 10,
					pageNumber2: 1,
					// firstdaystatus:false,
					listid:'',
					listtype:'',
					form:{
						keyword:''
					}
				},
				methods: {
					toSearchc(){
						console.log('..........1');
						getDateLeft('down');
					},
					deleteName(id){
						//删除人员
						plus.nativeUI.showWaiting('正在删除');
						mui.baseApp.httpRequst('/api/v2/sbxj/removeHelperUser', {
								ids:id
							},
							function(rs) {
								console.log('删除结果...'+JSON.stringify(rs));
								getDateLeft('down');
							}
						);
					},
					handleTask(item,type){
						var btnArray = ['取消', '确认'];
						mui.confirm('请确认是否协助巡检工作', '', btnArray, function(e) {
							if (e.index == 1) {
								plus.nativeUI.showWaiting('正在提交');
								mui.baseApp.httpRequst('/api/v2/sbxj/UpdateHelperStatus', {
										id:item.helperid,
										status: type
									},
									function(rs) {
										console.log('同意还是拒绝...'+JSON.stringify(rs));
										getDateLeft('down');
									}
								);
							} else {
								
							}
						})
					},
					getTask(item,type){
						if(item.status != '1'){
							return;
						}
						var btnArray = ['取消', '确定'];
						mui.confirm('您是否要领取任务？', '提示', btnArray, function(e) {
							if (e.index == 1) {
								plus.nativeUI.showWaiting('任务领取中');
								mui.baseApp.httpRequst('/api/v2/sbxj/recieveWindXjTask', {
										xsdWindId:item.id,
										memberId: localStorage.getItem('userid')
									},
									function(rs) {
										console.log('任务领取'+JSON.stringify(rs));
										if(rs.status != 200){
											plus.nativeUI.closeWaiting();
											mui.toast(rs.message)
										}else{
											getDateLeft('down');
											if(type == '1'){
												var arr = plus.storage.getItem('pc') || '[]';
												arr = JSON.parse(arr);
												console.log('item',JSON.stringify(item));
												arr.push(item)
												plus.storage.setItem('pc', JSON.stringify(arr));
											}else{
												var arr = plus.storage.getItem('xl') || '[]';
												arr = JSON.parse(arr);
												arr.push(item)
												plus.storage.setItem('xl', JSON.stringify(arr));
											}
											vm.getChild(item,type);
										}
									}
								);
							} 
						})
					},
					getChild(item,type){
						mui.baseApp.httpRequst('/api/v2/sbxj/notXjListByXsdWind', {
								wind:org_code1,
								xsdWindId:item.id,
								memberId:localStorage.getItem('userid')
							},
							function(res) {
								if(type == '1'){
									var arr = plus.storage.getItem('pcchild') || '[]';
									arr = JSON.parse(arr);
									arr.push({
										key:item.id,
										value:res.data.list
									})
									plus.storage.setItem('pcchild', JSON.stringify(arr));
								}else{
									var arr = plus.storage.getItem('xlchild') || '[]';
									arr = JSON.parse(arr);
									arr.push({
										key:item.id,
										value:res.data.list
									})
									plus.storage.setItem('xlchild', JSON.stringify(arr));
								}
							}
						);
					},
					getReList(type){
						var that = this;
						mui.baseApp.httpRequst('/api/v2/sbxj/findXsdWindList', {
								wind: org_code1,
								status: '1,2',
								type: type,
								memberId: localStorage.getItem('userid')
							},
							function(res) {
								if (res.status == 400) {
									mui.toast(res.message);
									return;
								}
								if (type == '1') {
									that.ifshow = false;
									if (res.data.length == 0) {
										that.ifshow = true;
									}
									console.log('频次......' + JSON.stringify(res));
									that.data = res.data;
									// for (var i = 0; i < res.data.length; i++) {
									// 	//存一个状态，只要有天巡检第1次，无论是否开始巡检，就可以判断天巡检第2次不能巡
									// 	if (res.data[i].rate == 0 && ~res.data[i].name.indexOf('天巡检第1次')) {
									// 		that.firstdaystatus = true;
									// 	}
									// }
								} else {
									that.ifshow2 = false;
									if (res.data.length == 0) {
										that.ifshow2 = true;
									}
									console.log('线路......' + JSON.stringify(res));
									that.data2 = res.data;
								}
							}
						);
					},
					getChildPage(item){
						var sbid = item.id;
						var name = item.name;
						var title = name.substring(5);
						var type = item.status;
						var rate = item.rate;
						var status = item.sxlstatus;
						console.log('status=' + status);
						
						if (status == '1' && type == '1') {
							mui.toast('巡检任务已被锁定，请先完成巡检中的任务，联系管理员解锁');
							return;
						}
						// if (rate == 0 && (firstdaystatus || vm.firstdaystatus) && ~name.indexOf('天巡检第2次')) {
						// 	mui.toast('请先巡检第一次天巡检');
						// 	return;
						// }
						if(type == '1'){
							mui.toast('请先领取任务');
							return;
						}
						mui.openWindow({
							url: '../weixunjianlist.html',
							id: 'weixunjianlist.html',
							extras: {
								sbid: sbid,
								rate: rate,
								title: title,
								scantype:item.helpstatus,
								xjtype:'pinci'
							},
							createNew: false, //是否重复创建同样id的webview，默认为false:不重复创建，直接显示
						})
					},
					getChildPage3(item){
						var sbid = item.id;
						var name = item.name;
						var type = item.status;
						var rate = item.rate;
						var status = item.sxlstatus;
						console.log('status=' + status);
						if (status == '1' && type == '1') {
							mui.toast('巡检任务已被锁定，请先完成巡检中的任务，联系管理员解锁');
							return;
						}
						if(type == '1'){
							mui.toast('请先领取任务');
							return;
						}
						mui.openWindow({
							url: '../weixunjianlist.html',
							id: 'weixunjianlist.html',
							extras: {
								sbid: sbid,
								rate: rate,
								title: name,
								scantype:item.helpstatus,
								xjtype:'xianlu'
							},
							createNew: false, //是否重复创建同样id的webview，默认为false:不重复创建，直接显示
						})
					},
					getPeople(item,type){
						console.log('item=',item);
						console.log('item.id=',item.id);
						this.listtype = type;
						this.listid = item.id;
						mui.openWindow({
							id: "../selectpeople.html",
							url: "../selectpeople.html",
							extras: {
								type: type,
								iid:item.id,
								from:'syz'
							},
							waiting: {
								autoShow: false
							}
						});
					},
					getVisible(item,type) {
						item.visible = item.visible == 0 ? 1 : 0;
						if(type){
							var that = this;
							// plus.nativeUI.showWaiting();
							mui.baseApp.httpRequst('/api/v2/sbxj/findUserInfoByXjId', {
									datumId: item.id,
									type: type == 'sb' ? 2 : 1
								},
								function(res) {
									// plus.nativeUI.closeWaiting();
									item = Object.assign(item,res.data);
									that.$forceUpdate();
								}
							);
						}
					},
					getType(type) {
						var ratetext = '';
						if (type == '0') {
							ratetext = '天'
						} else if (type == '1') {
							ratetext = '周'
						} else if (type == '2') {
							ratetext = '月'
						} else if (type == '3') {
							ratetext = '季'
						} else if (type == '4') {
							ratetext = '半年'
						}
						return ratetext;
					},
					changeState: function(cs) {
						var curyear = new Date().getFullYear();
						if (cs && ~cs.indexOf(curyear)) {
							cs = curyear + cs.split(curyear)[1];
						}
						return cs;
					},
					getTabtn(index) {
						vm.tabindex = index;
						if (index == 2) {
							if(vm.ifshow1){
								document.querySelector('.scanfix').style.display = 'none';
							}else{
								document.querySelector('.scanfix').style.display = 'block';
							}
						} else {
							document.querySelector('.scanfix').style.display = 'none';
						}
					},
					getCheckTime(d) {
						var curd = new Date().getTime();
						var actived = 0;
						if (d) {
							actived = new Date(Date.parse(d)).getTime();
							if (actived < curd) {
								return 'red'
							}
							if (actived - curd < 86400000) {
								return 'yellow'
							}
						}
						return 'normal';
					}
				}
			});
			mui.plusReady(function() {
				var org_code = localStorage.getItem('org_code'); //获取缓存中的风场编号
				org_code1 = JSON.parse(org_code);
				console.log('org_code1', org_code1);
				checkLock(); //检查列表是否被锁定
			})
			
			function checkLock() {
				plus.nativeUI.showWaiting();
				mui.baseApp.httpRequst('/api/v2/sbxj/findWindLockStatus', {
						wind: org_code1
					},
					function(res) {
						console.log('temp......' + JSON.stringify(res));
						islock = res.data.lockStatus;
						// getDateLeft('up')
					}
				);
			}
			
			function getDateLeft(type) {
				if(type == 'down'){
					vm.pageSize = 10;
					vm.pageNumber = 1;
				}
				mui.baseApp.httpRequst('/api/v2/sbxj/findXsdWindList', {
						wind: org_code1,
						status: '1,2',
						type: 1,
						pageSize: vm.pageSize,
						pageNumber: vm.pageNumber,
						memberId: localStorage.getItem('userid')
					},
					function(res) {
						plus.nativeUI.closeWaiting()
						if (res.status == 400) {
							mui.toast(res.message);
							return;
						}
						if(type == 'down'){
							vm.data = []
						}
						console.log(JSON.stringify(res.data));
						var data = res.data.list;
						if (data.length < 10) {
							vm.data = vm.data.concat(data);
							mui('#refreshContainer').pullRefresh().endPullupToRefresh(true);
							if(type=='down'){
								setTimeout(function() {
									mui('#refreshContainer').pullRefresh().endPulldownToRefresh()
								}, 1000);
							}
							if(data.length == 0){
								vm.ifshow = true;
							}
						} else {
							vm.data = vm.data.concat(data);
							vm.pageNumber++;
							if(type == 'up'){
								mui('#refreshContainer').pullRefresh().endPullupToRefresh(false);
							}else{
								setTimeout(function() {
									mui('#refreshContainer').pullRefresh().endPulldownToRefresh()
								}, 1000);
							}
						}
					}
				);
			}
			
			
			function pulldown(){
				getDateLeft('down');
			}
			
			function pullup(){
				getDateLeft('up');
			}
			
			//当前时间大于开始时间，才能巡检
			function getCheckIfClick(d) {
				var curd = new Date().getTime();
				var newd = 0;
				if (d) {
					newd = new Date(Date.parse(d)).getTime();
				}
				return curd > newd ? 'true' : 'false';
			}
			//判断结束时间是否大于当前时间
			function getCheckTime(d) {
				var curd = new Date().getTime();
				var actived = 0;
				if (d) {
					actived = new Date(Date.parse(d)).getTime();
					if (actived < curd) {
						return 'red'
					}
					if (actived - curd < 86400000) {
						return 'yellow'
					}
				}
				return 'normal';
			}
			
			function setPeoples(persons){
				plus.nativeUI.showWaiting('设置人员中');
				mui.baseApp.httpRequst('/api/v2/sbxj/setXsdHelperUser', {
						datumId: vm.listid,
						type: vm.listtype,
						helperIds: persons
					},
					function(res) {
						console.log('res=' + JSON.stringify(res));
						getDateLeft('down');;
					}
				);
			}
			
			window.addEventListener('refresh', function(e) { //执行刷新
				getDateLeft('down');
			});
			
			window.addEventListener('refresh2', function(e) { //执行刷新
				getDateLeft('down');
			});
			
			window.addEventListener('refresh1', function(e){//执行刷新
				var persons = e.detail.persons;
				persons = persons.join(',');
				if(persons != ''){
					setPeoples(persons);
				}
			})
			
			function toSearch(){
				getDateLeft('down');
				
			}
		</script>
	</body>

</html>